package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.entity.Drug;
import com.qianfeng.entity.DrugRegistration;
import com.qianfeng.entity.Registration;
import com.qianfeng.service.DrugService;
import com.qianfeng.service.RegistrationService;
import com.qianfeng.service.SendDrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
public class SendDrugController {
    @Autowired
    private DrugService drugService;
    @Autowired
    private RegistrationService registrationService;
    @Autowired
    private SendDrugService sendDrugService;

    @RequestMapping("/getSendDrugList")
    public String getSendDrugList(){
        return "05_in_the_hospital_medicine";
    }
    @ResponseBody
    @RequestMapping("/getSendDrugPage")
    public Page getSendDrugPage(Integer pageNo,Integer pageSize){
        int pageNo_=1;
        int pageSize_=2;
        if (pageNo!=null){
            pageNo_=pageNo;
        }
        if (pageSize!=null){
            pageSize_=pageSize;
        }
        Page page = sendDrugService.getgetSendDrugPage(pageNo_, pageSize_);
        return page;
    }
    @RequestMapping("/jumpSendMedicine")
    public String jumpSendMedicine(Integer rId, Map map){
        Registration registration = registrationService.getRegistrationById(rId);
        map.put("registration",registration);
        List<Drug> drugList = drugService.getDrugList();
        map.put("drug",drugList);
        return "05_01_in_the_hospital_send_medicine";
    }
    @RequestMapping("/sendMedicine")
    public String sendMedicine(DrugRegistration drugRegistration){
        drugRegistration.setDreTime(new Date());
        sendDrugService.addSendDrug(drugRegistration);
        return "05_in_the_hospital_medicine";
    }
    @RequestMapping("/medicineDetail")
    public String medicineDetail(Integer rId,Map map){
        List<DrugRegistration> sendDrugListByRId = sendDrugService.getSendDrugListByRId(rId);
        map.put("sendDrug",sendDrugListByRId);
        return "05_02_in_the_hospital_medicine_detail";
    }

    @RequestMapping("/send1")
    public String send1(Integer dreId){
        DrugRegistration drugRegistration = new DrugRegistration();

        drugRegistration.setDreId(dreId);


        System.out.println("drugRegistration==="+drugRegistration);

        sendDrugService.updateSendDrug1(drugRegistration);
        return "05_in_the_hospital_medicine";
    }
    @RequestMapping("/send5")
    public String send5(Integer dreId){
        DrugRegistration drugRegistration = new DrugRegistration();
        drugRegistration.setDreId(dreId);
        sendDrugService.updateSendDrug5(drugRegistration);
        return "05_in_the_hospital_medicine";
    }
    @RequestMapping("/send30")
    public String send30(Integer dreId){
        DrugRegistration drugRegistration = new DrugRegistration();
        drugRegistration.setDreId(dreId);
        sendDrugService.updateSendDrug30(drugRegistration);
        return "05_in_the_hospital_medicine";
    }

    @RequestMapping("/sendAll")
    public String sendAll(Integer dreId){
        DrugRegistration drugRegistration = new DrugRegistration();
        drugRegistration.setDreId(dreId);
        sendDrugService.updateSendDrugAll(drugRegistration);
        return "05_in_the_hospital_medicine";
    }




}
